package com.gin.kotlin.no_gay_alliance.fragment.main.setting

import com.gin.kotlin.no_gay_alliance.R
import com.gin.kotlin.no_gay_alliance.activity.MoreBanConfigActivity
import com.gin.kotlin.no_gay_alliance.activity.emoji.EmojiConfigActivity
import com.gin.kotlin.no_gay_alliance.activity.replyhistory.ReplyHistoryConfigActivity
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingFragment
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingRecyclerViewAdapter
import com.gin.kotlin.no_gay_alliance.databinding.FragmentMainSettingEnhancementsBinding
import com.gin.kotlin.no_gay_alliance.databinding.ItemEnhancementBinding
import com.gin.kotlin.no_gay_alliance.model.EnhancementModel

/**
 * 增强功能配置入口
 */
class EnhancementsConfigFragment : AbstractBindingFragment<FragmentMainSettingEnhancementsBinding>() {

    private lateinit var enhancements: List<EnhancementModel>

    override fun onCreateView() {
        val b = this.b ?: return
        this.enhancements = listOf(
            EnhancementModel(R.string.reply_history, R.string.reply_history_description) { ReplyHistoryConfigActivity.start(requireContext()) },
            EnhancementModel(R.string.more_ban, R.string.more_ban_description) { MoreBanConfigActivity.start(requireContext()) },
            EnhancementModel(R.string.emoji, R.string.emoji_description) { EmojiConfigActivity.start(requireContext())},
        )
        b.recyclerView.adapter = object : AbstractBindingRecyclerViewAdapter<ItemEnhancementBinding, EnhancementModel>(requireContext(),handler!!) {
            override fun onBindViewHolder(holder: ViewHolder<ItemEnhancementBinding>, position: Int, b: ItemEnhancementBinding, dataModel: EnhancementModel) {
                b.tvName.text = getString(dataModel.name)
                b.tvDescription.text = getString(dataModel.description)
                b.btConfig.tag = dataModel
                b.btConfig.setOnClickListener {  (it.tag as? EnhancementModel)?.onClick?.invoke() }
            }
        }.also { it.replaceData(enhancements) }

    }
}